home *** CD-ROM | disk | FTP | other *** search
- /*
- File: RlShlEv.cpp
-
- Contains: Apple Event handlers for the document shell.
-
- Owned by: Eric House
-
- Copyright: © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <5> 7/11/96 TJ Quit event does not return an error
- <4> 6/20/96 JP 1339269: Made quit handle the saving
- parameter too
- <3> 5/31/96 jpa T10012: Fixed 'oapp', 'odoc', 'pdoc'
- handlers for app-style (CyberDog) process
- model.
- <2> 5/8/96 NP 1304875: Infinite Save Changes dialog boxes
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _PLFMDEF_
- #include <PlfmDef.h>
- #endif
-
- #ifndef _SIHELPER_
- #include <SIHelper.h>
- #endif
-
- #ifndef _ODPRCS_
- #include "ODPrcs.h"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef SOM_ShellSI_xh
- #include "ShellSI.xh"
- #endif
-
- #ifndef _RLSHELL_
- #include "RlShell.h"
- #endif
-
- #ifndef _SEUTILS_
- #include <SEUtils.h>
- #endif
-
- #ifndef _SHPRPACC_
- #include "ShPrpAcc.h"
- #endif
-
- #ifndef _SHLEVTHD_
- #include "ShlEvtHd.h"
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef _RLSHELL_
- #include "RlShell.h"
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _DOCUTILS_
- #include <DocUtils.h>
- #endif
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef _ODDESUTL_
- #include <ODDesUtl.h>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODNameResolver_xh
- #include <NamRslvr.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODMessageInterface_xh
- #include <MssgIntf.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODWindowIterator_xh
- #include <WinIter.xh>
- #endif
-
- #ifndef SOM_ODOSLToken_xh
- #include <ODOSLTkn.xh>
- #endif
-
- #ifndef SOM_ODAppleEvent_xh
- #include <ODAplEvt.xh>
- #endif
-
- #ifndef __ASREGISTRY__
- #include <ASRegistry.h>
- #endif
-
- #ifndef __AEUserTermTypes__
- #include <AEUserTermTypes.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_ODRegistry_defined
- #include "ODRgstry.xh"
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #pragma segment ShellEvt
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- #define STATICBUILD
-
- const DescType kShellPropAccessor = 0x73706163; // 'spac';
- const DescType kShellSelfPropAccessor = 0x7368656C; // 'shel';
-
- const DescType kShellEventHandler = 'shev';
-
- //==============================================================================
- // Function Prototypes
- //==============================================================================
-
- //void CreateUniqueTmpFolderForFile(ODFileSpec* result, Str63 fileName);
-
- #define HANDLER_PARAMS \
- ODPart* thePart, \
- ODAppleEvent* message, \
- ODAppleEvent* reply, \
- ODSLong handlerRefcon
-
- // pascal ODError HandleClone(HANDLER_PARAMS);
- pascal ODError HandleClose(HANDLER_PARAMS);
- // pascal ODError HandleCountEl(HANDLER_PARAMS);
- // pascal ODError HandleMake(HANDLER_PARAMS);
- // pascal ODError HandleDelete(HANDLER_PARAMS);
- // pascal ODError HandleDoExist(HANDLER_PARAMS);
- // pascal ODError HandleGetClsInfo(HANDLER_PARAMS);
- // pascal ODError HandleGetData(HANDLER_PARAMS);
- // pascal ODError HandleGetDataSz(HANDLER_PARAMS);
- // pascal ODError HandleGetEvnInfo(HANDLER_PARAMS);
- // pascal ODError HandleMove(HANDLER_PARAMS);
- // pascal ODError HandleOpen(HANDLER_PARAMS);
- // pascal ODError HandlePrint(HANDLER_PARAMS);
- pascal ODError HandleSave(HANDLER_PARAMS);
- // pascal ODError HandleSetData(HANDLER_PARAMS);
- pascal ODError HandleODActivate(HANDLER_PARAMS);
-
- pascal ODError HandleGetAETE(HANDLER_PARAMS);
-
- #undef HANDLER_PARAMS
-
- pascal ODError GetFileFromNULL( ODPart* part,
- DescType desiredClass,
- ODOSLToken* container,
- DescType containerClass,
- DescType form,
- ODDesc* selectionData,
- ODOSLToken* value,
- ODSLong refCon);
-
-
- ShellEventHandler* GetHandlerFromAEVT(AppleEvent* theAppleEvent,
- RealShell* self);
- void GetDirectParam(RealShell* self, AppleEvent* theAppleEvent,
- AEDesc* evtDp);
-
- //==============================================================================
- // RealShell
- //==============================================================================
-
- //-------------------------------------------------------------------------------------
- // Apple Event Initialization
- //-------------------------------------------------------------------------------------
-
-
- void RealShell::InitAE()
- {
- Environment* ev = fEV;
-
- ShellSI* shellSemtInterface = new ShellSI;
- THROW_IF_NULL(shellSemtInterface);
- fSIHelper = new SIHelper;
- fSIHelper->InitSIHelper(fSession, shellSemtInterface);
- shellSemtInterface->InitCPlusSemanticInterface(ev, kODAppShell, fSIHelper,
- fSession);
- fSession->SetShellSemtInterface(ev, shellSemtInterface);
- shellSemtInterface->Release(ev); // SetShellSemtInterface acquires.
-
- ODObjectAccessorUPP newAccessor =
- NewODObjectAccessorProc( GetFileFromNULL );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallObjectAccessor( cFile,
- typeNull, newAccessor, (ODSLong)fSession );
-
- ODEventHandlerUPP newHandler =
- NewODEventHandlerProc( RealShell::HandleOpenAppEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEOpenApplication,
- newHandler,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleOpenPrintDocsEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEOpenDocuments,
- newHandler,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleOpenPrintDocsEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEPrintDocuments,
- newHandler ,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleQuitEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEQuitApplication,
- newHandler ,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleLaunchFailedEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
- kCFMLaunchFailedEventClass,
- kCFMLaunchFailedEventID,
- newHandler ,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleODActivate );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
- kAEOpenDocSuite,
- kODActivateEvent,
- newHandler ,
- (long)this);
-
- ODCoercionHandlerUPP fsSpecCoerceHdlr =
- NewODDescCoercionHandlerProc( RealShell::CoerceToFSSpec );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallCoercionHandler( typeAlias, typeFSS,
- fsSpecCoerceHdlr, (long)this, kODTrue );
-
- // this->InstallObjectAccessors(shellSemtInterface);
-
- /*
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallCoercionHandler(typeChar, typeFSS,
- (XMPCoercionHandler)Pathname2FSSpec, kNoRefCon,
- kFromTypeIsNotDesc );
- */
-
- ODEventHandlerUPP eventHandlerUPP;
-
- #ifdef TO_BE_DELETED
- eventHandlerUPP = NewODEventHandlerProc(HandleClone);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEClone,
- eventHandlerUPP, (ODSLong)this);
- #endif /* TO_BE_DELETED */
-
- eventHandlerUPP = NewODEventHandlerProc(HandleClose);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEClose,
- eventHandlerUPP, (ODSLong)this);
-
- #ifdef TO_BE_DELETED
- eventHandlerUPP = NewODEventHandlerProc(HandleCountEl);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAECountElements,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleMake);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAECreateElement,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleDelete);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEDelete,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleDoExist);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEDoObjectsExist,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetClsInfo);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetClassInfo,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetData);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetData,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetDataSz);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetDataSize,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetEvnInfo);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetEventInfo,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleMove);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEMove,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleOpen);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEOpen,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandlePrint);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEPrint,
- eventHandlerUPP, (ODSLong)this);
- #endif /* TO_BE_DELETED */
-
- eventHandlerUPP = NewODEventHandlerProc(HandleSave);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAESave,
- eventHandlerUPP, (ODSLong)this);
-
- #ifdef TO_BE_DELETED
- eventHandlerUPP = NewODEventHandlerProc(HandleSetData);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAESetData,
- eventHandlerUPP, (ODSLong)this);
- #endif /* TO_BE_DELETED */
-
- //#ifndef STATICBUILD
- // Just let AS get the resource directly if not ASLM. In fact, we
- // probably don't need this even in that case.
- eventHandlerUPP = NewODEventHandlerProc(HandleGetAETE);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAEOpenDocSuite, kGetAETE,
- eventHandlerUPP,
- (ODSLong)this);
- //#endif /* STATICBUILD */
-
- }
-
-
- void RealShell::HandleHighLevelEvent(ODEventData* event)
- {
- Environment* ev = fEV;
- ProcessSerialNumber myPSN,frontPSN;
- ODBoolean active;
- (void)GetCurrentProcess(&myPSN);
- (void)GetFrontProcess(&frontPSN);
- (void)SameProcess(&myPSN,&frontPSN,&active);
- if (active)
- this->UpdateMenus();
-
- if ( ((AEEventClass) event->message == 'aevt') && (*(AEEventID *) &(event->where) == 'odoc') )
- {
- // If the open document event was sent by the edition manager, the modifiers field
- // of the event will be garbage. This can cause AEProcessAppleEvent to return an error
- // instead of calling one of our event handlers.
- // We work around this by clearing the modifiers field. Note that clearing the field
- // is not correct if the event is larger than 64K; we take the chance that an 'odoc'
- // event won't be this large. [cc 7/19/95] [Radar #1261856]
- event->modifiers = 0;
- }
-
- ODBoolean succeeded = fSession->GetMessageInterface(ev)->ProcessSemanticEvent(ev, event);
- }
-
-
- //-------------------------------------------------------------------------------------
- // Handling 'oapp' Events
- //-------------------------------------------------------------------------------------
-
-
- pascal ODError RealShell::HandleOpenAppEvent(ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- long refCon)
- {
- /* Called when a stub application is starting up the OpenDoc shell
- at launch time -- e.g. CyberDog. */
-
- ODUnused(part);
- ODUnused(message);
- ODUnused(reply);
-
- RealShell* self = (RealShell*)refCon;
- Environment* ev = self->fEV;
- ODError error = noErr;
-
- TRY
-
- // Determine location (FSSpec) of current app:
- ProcessInfoRec info;
- FSSpec appLoc;
- self->GetCurrentProcessInfo(&info,NULL,&appLoc);
-
- TempPlatformFile file = new PlatformFile;
- file->Specify(&appLoc);
- self->OpenFile(file,kODTrue); // Force it to open APPL
-
- CATCH_ALL
- error = ErrorCode();
- self->GetSession()->GetDispatcher(ev)->Exit(ev);
- self->SetAEError(error);
- ENDTRY
-
- return error;
- }
-
-
- //-------------------------------------------------------------------------------------
- // Handling 'odoc' and 'pdoc' Events
- //-------------------------------------------------------------------------------------
-
-
- void RealShell::FakePrintMenuEvent()
- {
- Environment* ev = fEV;
- ODDispatcher* dispatcher = this->GetSession()->GetDispatcher(ev);
-
- ODMenuID menu;
- ODMenuItemID menuItem;
- TempODMenuBar baseMenuBar = this->fWindowState->AcquireBaseMenuBar(ev);
- baseMenuBar->GetMenuAndItem(ev, kODCommandPrint, &menu, &menuItem );
-
- ODEventData event;
- event.message = (menu<<16) | menuItem;
- event.what = kODEvtMenu;
- // zero the rest of the fields
- WASSERT( sizeof(Point) == sizeof(long) ); // this is gross but
- *(long*)&event.where = 0L;
- event.when = 0L;
- event.modifiers = 0;
- dispatcher->Dispatch(ev, &event);
- }
-
-
- pascal ODError RealShell::HandleOpenPrintDocsEvent( ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- long refCon)
- {
- ODUnused(part);
- ODUnused(reply);
-
- RealShell* self = (RealShell*)refCon;
- Environment* ev = self->fEV;
- ODSession* session = self->GetSession();
- ODVolatile(session);
-
- long itemsInList;
- ODError error = noErr;
- AppleEvent realMessage;
- DescType eventID;
- DescType ignoreType;
- Size ignoreActual;
-
- TRY
-
- // get list of documents
- realMessage.dataHandle = kODNULL;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- TempAEDescStruct docList;
- THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyDirectObject, typeAEList,
- &docList));
- THROW_IF_ERROR( AEGetAttributePtr( &realMessage, keyEventIDAttr, typeType,
- &ignoreType, &eventID, sizeof(eventID), &ignoreActual ));
- ODBoolean isPrint = eventID == kAEPrintDocuments;
- if (MissingParams(&realMessage))
- THROW( errAEParamMissed );
-
- // Iterate through all documents and open them:
- THROW_IF_ERROR( AECountItems(&docList, &itemsInList ));
- for (ODSLong index = 1; index <= itemsInList; index++) {
-
- ODFileSpec fileSpec;
- AEKeyword key,type;
- Size size;
- OSErr err = AEGetNthPtr(&docList, index, typeFSS, &key,&type,
- &fileSpec,sizeof(fileSpec),&size);
- if (err == errAECoercionFail)
- {
- // We'll handle tokens here...
- TempAEDescStruct coerceDesc, fileDesc;
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
-
- GetDirectParam(self, &realMessage, &coerceDesc);
- THROW_IF_ERROR( AEDescToODDesc(&coerceDesc, tmpWrapper ) );
- ODDesc* myToken;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- myToken = resolver->GetUserToken(ev, tmpWrapper);
- AEDisposeDesc( &coerceDesc );
- THROW_IF_ERROR( ODDescToAEDesc(myToken, &coerceDesc) );
- THROW_IF_ERROR( AECoerceDesc(&coerceDesc, typeFSS, &fileDesc) );
- ODBlockMove(*fileDesc.dataHandle,&fileSpec,sizeof(fileSpec));
- err = noErr;
- }
-
- // If printing, open each document in this process, then print and close it.
- // If this is an application process (CyberDog), open all documents in this process.
- // If this is a normal document process, open the first document in this process
- // if no document is open, and open the rest in separate processes.
- if( !err ) {
- TempPlatformFile file = new PlatformFile();
- file->Specify(&fileSpec);
- if( isPrint ) {
- ODDocument *doc = self->OpenFile(file);
- if( doc ) {
- self->FakePrintMenuEvent();
- if (ODCloseDocument(ev, session, doc))
- session->GetDispatcher(ev)->Exit(ev);
- }
- } else if( self->fAPPLProcess || (index==1 && ODGetFirstOpenDocument(ev, session)==kODNULL) )
- self->OpenFile(file);
- else
- self->OpenAnotherFile(file);
- }
- }
-
- CATCH_ALL
- error = ErrorCode();
- session->GetDispatcher(ev)->Exit(ev);
- self->SetAEError(error);
- ENDTRY
- ODDisposeAppleEvent( &realMessage );
-
- return error;
- } // HandleOpenPrintDocsEvent()
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleQuitEvent
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- pascal ODError RealShell::HandleQuitEvent( ODPart* /*part*/,
- ODAppleEvent* message,
- ODAppleEvent* /*reply*/,
- long refCon)
- {
- ODError error = noErr;
- RealShell* self = (RealShell*)refCon;
- Environment* ev = self->fEV;
- ODSession* session = self->GetSession();
- ODDescType yesNoAsk = kAEAsk;
- ODDescType theType;
- ODSLong theSize;
- AEDesc event;
-
- TRY
- ODDescToAEDesc(message, &event);
- error = AEGetParamPtr(&event, keyAESaveOptions, typeEnumerated, &theType, &yesNoAsk, sizeof(yesNoAsk), &theSize);
- // we don't throw because we're quitting and don't care if there's an error
- error = noErr; // to keep it from being returned
-
- // In OpenDoc the 'QUIT' event means CloseDocument.
-
- RealShell* self = (RealShell*)refCon;
- ODDocument* document = kODNULL;
- while ((document = ODGetFirstOpenDocument(ev, session)) != kODNULL)
- {
- if (!self->CloseDocument(document, yesNoAsk))
- THROW(userCanceledErr);
- }
- session->GetDispatcher(ev)->Exit(ev);
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } // HandleQuitEvent()
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleLaunchFailedEvent
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- pascal ODError RealShell::HandleLaunchFailedEvent( ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- long refCon)
- {
- ODUnused(part);
- ODUnused(reply);
-
- long launchErr;
- ProcessSerialNumber psn;
- Str255 appName, libName;
- AppleEvent realMessage;
-
- THROW_IF_ERROR(ODDescToAEDesc(message, &realMessage));
-
- //<eeh> any chance this can throw???
- GetLaunchFailedParams(&realMessage, launchErr,&psn,appName,libName);
- ODDisposeAppleEvent(&realMessage);
-
- RealShell *shell = (RealShell*)refCon;
- shell->LaunchFailed(launchErr,psn,appName,libName);
- return noErr;
- }
-
-
- void
- RealShell::LaunchFailed( ODSLong launchErr, const ProcessSerialNumber &psn,
- Str255 appName, Str255 libName )
- {
- if( psn.lowLongOfPSN != kNoProcess ) {
- Boolean result;
- if( SameProcess(&psn,&fLastNewDocPSN,&result) == noErr && result != kODFalse ) {
- // This is a new document we just created & launched; better delete it.
- OSErr err= FSpDelete(&fLastNewDocSpec);
- if( err )
- WARN("Error %d trying to delete new document",err);
- fLastNewDocPSN.lowLongOfPSN = kNoProcess;
- fLastNewDocSpec.name[0] = '\0';
- }
- }
-
- this->ExceptionAlert(launchErr,kODNULL);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleODActivateEvent
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- pascal ODError RealShell::HandleODActivate( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
-
- ODError result = noErr;
-
- RealShell* self = (RealShell*)handlerRefcon;
-
- ODFileSpec fileSpec;
- AppleEvent realMessage;
- DescType unused1;
- Size unused2;
- ODBoolean wasPrintEvent = kODFalse;
- ODBoolean notAlreadyOpen = kODFalse;
- boolean quitAfterPrint = kODFalse;
- TempODDraft draftToBringForward = kODNULL;
-
- realMessage.dataHandle = NULL;
- TRY
- THROW_IF_ERROR(ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyDirectObject, typeFSS,
- &unused1, (Ptr)&fileSpec, sizeof(fileSpec), &unused2));
- DescType spawningEventID;
- OSErr err = AEGetParamPtr(&realMessage, keyODActivateEventCause,
- typeType, &unused1, (Ptr)&spawningEventID,
- sizeof(spawningEventID), &unused2 );
- if ( err == noErr )
- wasPrintEvent = spawningEventID == kAEPrintDocuments;
- // else drop the error: id not present is ok.
-
- err = AEGetParamPtr( &realMessage, keyODRefnumFromResource,
- typeBoolean, &unused1, (Ptr)&quitAfterPrint,
- sizeof(quitAfterPrint), &unused2 );
- if ( err != noErr )
- quitAfterPrint = kODFalse;
-
- CATCH_ALL
- result = ErrorCode();
- ENDTRY
- ODDisposeAppleEvent(&realMessage);
-
- Environment* ev = self->fEV;
- ODSession* session = self->GetSession();
-
- if ( result == noErr )
- {
- ODULong refNumCount, i;
- ODSShort* refNums = kODNULL;
- GetLocalPaths(&fileSpec, kDataFork, &refNumCount, &refNums);
-
- if (refNumCount != 0)
- {
- for ( i=0; i<refNumCount; ++i)
- {
- ODDocument* doc = ODGetOpenDocumentFromRefNum(ev,
- session, refNums[i]);
- if ( doc != kODNULL )
- {
- draftToBringForward = ODGetTempDraftFromOpenDocument( ev,
- session, doc );
-
- if (draftToBringForward)
- draftToBringForward->Acquire(ev); // balance destructor of TempRef
- else
- draftToBringForward =
- doc->AcquireDraft(ev,kODDPReadOnly,0,kODNULL,kODPosTop,kODFalse);
-
- break; // exit for loop
- }
- }
-
- if (refNums)
- DisposePtr((Ptr)refNums);
- }
- else // *if* this process is supposed to handle this event at
- { // all, the ODActivate must have come because of a resource
- // fork.
- short resRefNum = CurResFile();
- if ( refNums != kODNULL )
- {
- DisposePtr( (Ptr)refNums );
- refNums = kODNULL;
- }
- GetLocalPaths( &fileSpec, kResourceFork, &refNumCount, &refNums );
- for ( i=0; i<refNumCount; ++i )
- {
- if ( refNums[i] == resRefNum ) // it belongs in this process
- {
- TempPlatformFile file = new PlatformFile;
- file->Specify( &fileSpec );
- draftToBringForward = ODOpenFileDocument( ev, session, file,
- kODDPSharedWrite );
-
- self->InstallShellPlugIns(draftToBringForward);
- notAlreadyOpen = kODTrue;
- break;
- }
- }
- if( refNums != kODNULL )
- DisposePtr( (Ptr)refNums );
- }
- }
-
- if ( draftToBringForward != kODNULL )
- {
- ProcessSerialNumber psn;
- GetCurrentProcess(&psn);
- SetFrontProcess(&psn);
-
- ODOpenDraft( ev, session, draftToBringForward );
- if ( notAlreadyOpen )
- {
- // the plugin may have patched these....
- self->fDispatcher = session->GetDispatcher(ev);
- self->fWindowState = session->GetWindowState(ev);
- }
- if ( wasPrintEvent )
- {
- self->FakePrintMenuEvent();
- if ( quitAfterPrint )
- {
- // need to release draft's refcount *before* calling
- // ODCloseDocument (or check with Tantek to see if
- // assertion in ODCloseDocument can be removed.
- ODDocument* doc = draftToBringForward->GetDocument(ev);
- draftToBringForward->Release(ev);
- draftToBringForward = kODNULL; // prevent another release by the TempRef
- ODBoolean wasLastDoc = ODCloseDocument( ev, session, doc );
- WASSERT( !wasLastDoc );
- }
- }
- }
-
- return result; // usually should be eventNotHandled?
- } // HandleODActivate
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // CoerceToFSSpec
- //
- ////////////////////////////////////////////////////////////////////////////////
-
-
- pascal ODError RealShell::CoerceToFSSpec( ODPart* thePart, ODDesc* theAEDesc,
- DescType toType, ODSLong handlerRefCon, ODDesc* result )
- {
- ODUnused(thePart);
- RealShell* self = (RealShell*)handlerRefCon;
-
- if (self->fAlreadyInCoercion)
- return errAECoercionFail;
- else
- self->fAlreadyInCoercion = kODTrue;
- ODError error = noErr;
-
- TRY
- TempAEDescStruct realInDesc;
- THROW_IF_ERROR( ODDescToAEDesc(theAEDesc, &realInDesc));
- if (realInDesc.descriptorType == typeAlias)
- {
- // use the built-in coercion first
- TempAEDescStruct tmpResult;
- error = AECoerceDesc( &realInDesc, toType, &tmpResult );
-
- if ( error == noErr )
- THROW_IF_ERROR( AEDescToODDesc( &tmpResult, result ));
- }
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- self->fAlreadyInCoercion = kODFalse;
- return error;
- } // CoerceToFSSpec()
-
- //----------------------------------------------------------------------------------------
- // RealShell::SetAEError
- //----------------------------------------------------------------------------------------
-
- void RealShell::SetAEError(ODError error)
- {
- fErrorFromOpenEvents = error;
- }
-
- //----------------------------------------------------------------------------------------
- // RealShell::GetAEError
- //----------------------------------------------------------------------------------------
-
- ODError RealShell::GetAEError()
- {
- return fErrorFromOpenEvents;
- }
-
- //==============================================================================
- // Functions
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // HandleGetAETE
- //------------------------------------------------------------------------------
-
-
- pascal ODError HandleGetAETE(ODPart* thePart,
- ODAppleEvent* theAppleEvent,
- ODAppleEvent* reply,
- ODSLong handlerRefcon)
- {
- ODUnused(thePart);
- ODUnused(handlerRefcon);
-
- AEDesc theAETE = NULL_DESCRIPTOR_DEFINITION;
- DescType returnedType;
- ODSize actualSize;
- ODSLong languageCode;
- ODError result;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- realMessage.dataHandle = realReply.dataHandle = NULL;
-
- TRY
- THROW_IF_ERROR( ODDescToAEDesc(theAppleEvent, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- result = AEGetParamPtr(&realMessage, keyDirectObject, typeLongInteger,
- &returnedType, (Ptr)&languageCode, sizeof(languageCode),
- (Size *)&actualSize);
- ODDisposeAppleEvent(&realMessage);
- THROW_IF_ERROR(result);
-
- TRY
- CUsingLibraryResources ref;
-
- theAETE.dataHandle = Get1Resource(typeAETE, (short)languageCode);
- if (theAETE.dataHandle)
- {
- theAETE.descriptorType = typeAETE;
- result = AEPutParamDesc(&realReply, keyAEResult, &theAETE);
- ReleaseResource(theAETE.dataHandle);
- THROW_IF_ERROR(result);
- }
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- THROW_IF_ERROR(error);
-
- THROW_IF_ERROR(AEDescToODDesc(&realReply, reply));
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
- AEDisposeDesc(&realReply);
-
- return error;
- } // HandleGetAETE()
-
-
- //------------------------------------------------------------------------------
- // GetFileFromNULL
- //------------------------------------------------------------------------------
-
- pascal ODError GetFileFromNULL( ODPart* part,
- DescType desiredClass,
- ODOSLToken* container,
- DescType containerClass,
- DescType form,
- ODDesc* selectionData,
- ODOSLToken* value,
- ODSLong refCon)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODSession* session = (ODSession*)refCon;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- ODError error = noErr;
- AEDesc aeAlias, tmp;
- char state;
-
- TRY
- // get the selectionData and coerce it into an fsspec
- THROW_IF_ERROR(ODDescToAEDesc(selectionData, &tmp));
- TempAEDesc tmpDesc(&tmp);
- state = HGetState(tmp.dataHandle);
- HLock(tmp.dataHandle);
- THROW_IF_ERROR(NewAliasMinimalFromFullPath(GetHandleSize(tmp.dataHandle),
- *tmp.dataHandle, "\p", "\p",
- (AliasHandle*)&aeAlias.dataHandle ));
- HSetState(tmp.dataHandle, state);
- aeAlias.descriptorType = typeAlias;
- TempAEDesc tmpDesc2(&aeAlias);
- UpdateUserToken(ev, resolver, value, &aeAlias);
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } // GetFileFromNULL
-
- //------------------------------------------------------------------------------
- // HandleClone
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleClone( ODPart* thePart, ODAppleEvent* theAppleEvent,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
-
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(theAppleEvent, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT( &realMessage,
- (RealShell*)handlerRefcon );
-
- AEDesc cloneLocation;
- THROW_IF_ERROR( AEGetParamDesc( &realMessage, keyAEInsertHere,
- typeInsertionLoc, &cloneLocation ) );
-
- AEDesc replyDp;
- handlerObj->Clone( &cloneLocation, &replyDp );
- delete handlerObj;
-
- THROW_IF_ERROR( AEPutParamDesc( &realReply, keyDirectObject, &replyDp ) );
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } // HandleClone()
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleClose
- //------------------------------------------------------------------------------
-
- pascal ODError HandleClose( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
-
- AEDesc theFile;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- // can't use TempAEDescs for these because they don't call
- // ODDisposeAppleEvent
- realMessage.dataHandle = realReply.dataHandle = NULL;
-
- TRY
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
- OSErr err = AEGetParamDesc(&realMessage, keyAEFile, typeFSS, &theFile);
- TempAEDesc tmpDesc(&theFile);
- ThrowIfNotAbsent(err);
-
- DescType saveOptions = kAEAsk, typeFound;
- Size actualSize;
- err = AEGetParamPtr(&realMessage, keyAESaveOptions, typeEnumeration,
- &typeFound, (Ptr)&saveOptions, sizeof(saveOptions), &actualSize);
- ThrowIfNotAbsent(err);
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
- handlerObj->Close(&theFile, saveOptions);
- delete handlerObj;
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- ODDisposeAppleEvent(&realMessage);
- ODDisposeAppleEvent(&realReply);
- return error;
- }
-
- //------------------------------------------------------------------------------
- // HandleCountEl
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleCountEl(ODPart* thePart, ODAppleEvent* message, ODAppleEvent* reply,
- ODSLong handlerRefcon)
- {
- ODUnused(thePart);
-
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
-
- DescType elemClass, typeFound;
- Size actualSize;
- THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyAEObjectClass, typeType,
- &typeFound, (Ptr)&elemClass, sizeof(elemClass), &actualSize));
-
- AEDesc replyDp;
- handlerObj->CountElements(elemClass, &replyDp);
- delete handlerObj;
-
- THROW_IF_ERROR(AEPutParamDesc(&realReply, keyDirectObject, &replyDp));
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleMake
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleMake(ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon)
- {
- ODUnused(thePart);
- ODUnused(handlerRefcon);
- ODUnused(reply);
-
- DescType newObjClass, typeFound;
- Size actualSize;
- AEDesc insertHere, newObjectName;
- OSErr err;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
-
- THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyAEObjectClass, typeType,
- &typeFound, (Ptr)&newObjClass, sizeof(newObjClass), &actualSize));
- THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyAEInsertHere,
- typeInsertionLoc, &insertHere));
- err = AEGetParamDesc(&realMessage, 'type', typeChar, &newObjectName);
- if (err && (err != errAEDescNotFound))
- THROW(err);
-
- err = AEGetParamDesc(&realMessage, 'subj', typeChar, &newObjectName);
- if (err && (err != errAEDescNotFound))
- THROW(err);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleDelete
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleDelete( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
- handlerObj->Delete();
- delete handlerObj;
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleDoExist
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleDoExist( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleGetClsInfo
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetClsInfo( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleGetData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetData( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(handlerRefcon);
-
- AEDesc evtDp;
- AEDesc replyDp;
- ODError error = noErr;
-
- RealShell* self = (RealShell*)handlerRefcon;
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- // ODOSLToken* tmpWrapper = kODNULL;
- TRY
-
- replyDp.dataHandle = NULL;
- evtDp.dataHandle = NULL;
-
- GetDirectParam((RealShell*)handlerRefcon, &realMessage,
- &evtDp);
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
-
- if( !resolver->IsODToken(ev, tmpWrapper) )
- THROW(errAEEventNotHandled);
- ODDesc* myTokenODDesc;
- myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- AEDesc myToken;
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken ));
- // ODDeleteObject(myTokenODDesc);
-
- switch( myToken.descriptorType )
- {
- case kShellSelfPropAccessor :
- case kShellPropAccessor :
- ShellPropAccessor* accessorObj =
- FIRSTBYTESFROMHANDLE((&myToken)->dataHandle,
- ShellPropAccessor*);
- accessorObj->GetPropertyData(&replyDp);
- delete accessorObj;
- break;
-
- default :
- THROW(errAEEventNotHandled);
- break;
- }
-
- THROW_IF_ERROR(AEPutParamDesc(&realReply, keyDirectObject, &replyDp));
- THROW_IF_ERROR( AEDescToODDesc(&realReply, reply ) );
-
- AEDisposeDesc(&evtDp);
- AEDisposeDesc(&replyDp);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- // ODDeleteObject(tmpWrapper);
- return error;
- } // HandleGetData();
- #endif /* TO_BE_DELETED */
-
-
- //------------------------------------------------------------------------------
- // HandleGetDataSz
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetDataSz( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleGetEvnInfo
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetEvnInfo( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleMove
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleMove( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleOpen
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleOpen( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandlePrint
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandlePrint( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleSave
- //------------------------------------------------------------------------------
-
- pascal ODError HandleSave( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
- AEDesc theFile;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- realMessage.dataHandle = realReply.dataHandle = NULL;
-
- TRY
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- OSErr err = AEGetParamDesc(&realMessage, keyAEFile, typeFSS, &theFile);
- ThrowIfNotAbsent(err);
-
- // keyAEFileType
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
- handlerObj->Save(&theFile /*,&theFileType*/);
- delete handlerObj;
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- ODDisposeAppleEvent(&realMessage);
- ODDisposeAppleEvent(&realReply);
- return error;
- } // HandleSave()
-
- //------------------------------------------------------------------------------
- // HandleSetData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleSetData( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
-
- AEDesc dataDesc;
- ODError error = noErr;
-
- RealShell* self = (RealShell*)handlerRefcon;
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- // THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- // ODOSLToken* tmpWrapper = kODNULL;
- TRY
-
- dataDesc.dataHandle = NULL;
- THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyAEData, typeWildCard,
- &dataDesc));
-
- AEDesc evtDp;
- GetDirectParam( self, &realMessage, &evtDp );
- AEDisposeDesc( &realMessage );
-
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
-
- if( !resolver->IsODToken(ev, tmpWrapper) )
- THROW(errAEEventNotHandled);
- ODDesc* myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- AEDesc myToken;
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken) );
-
- switch( myToken.descriptorType )
- {
- case kShellSelfPropAccessor :
- case kShellPropAccessor :
- ShellPropAccessor* accessorObj =
- FIRSTBYTESFROMHANDLE((&myToken)->dataHandle,
- ShellPropAccessor*);
- accessorObj->SetPropertyData(&dataDesc);
- delete accessorObj;
- break;
- default :
- THROW(errAEEventNotHandled);
- break;
- }
-
- AEDisposeDesc(&myToken);
- AEDisposeDesc(&dataDesc);
-
- CATCH_ALL
- AEDisposeDesc(&dataDesc);
- error = ErrorCode();
- ENDTRY
-
- // ODDeleteObject(tmpWrapper);
- return error;
- } // HandleSetData()
- #endif /* TO_BE_DELETED */
-
-
- //******************************************************************************
- // Utility functions
- //******************************************************************************
-
- ShellEventHandler* GetHandlerFromAEVT(AppleEvent* message,
- RealShell* self)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- AEDesc evtDp;
- THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
- &evtDp));
- TempAEDesc tmpdesc(&evtDp);
-
- ShellEventHandler* handlerObj;
- if (evtDp.descriptorType == typeNull)
- {
- handlerObj = new ShellEventHandler(typeNull, (ODObject*)self,
- (ODSLong)self);
- }
- else
- {
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
-
- if( !resolver->IsODToken(ev, tmpWrapper) )
- THROW(errAEEventNotHandled);
- ODDesc* myTokenODDesc;
- myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- AEDesc myToken;
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken ));
-
- handlerObj = FIRSTBYTESFROMHANDLE(myToken.dataHandle,
- ShellEventHandler*);
- AEDisposeDesc(&myToken);
- // ODDeleteObject(tmpWrapper);
- }
-
- // AEDisposeDesc(&evtDp);
- return handlerObj;
- } // GetHandlerFromAEVT()
-
-
- //------------------------------------------------------------------------------
- // GetDirectParam
- //------------------------------------------------------------------------------
-
- // THIS FUNCTION NEEDS A FIXIN' TO USE THE NEW WAY OF DOING DEFAULT ACCESSORS.
-
- void GetDirectParam(RealShell* self, AppleEvent* message,
- AEDesc* evtDp)
- {
- Environment* ev = somGetGlobalEnvironment();
- AEDesc localDP;
- THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
- &localDP));
-
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&localDP, tmpWrapper ) );
-
- ODBoolean istoken = resolver->IsODToken(ev, tmpWrapper) ;
- // ODDeleteObject(tmpWrapper);
- if ( istoken )
- {
- *evtDp = localDP;
- }
- else
- {
- WARN("RlShlEv.cpp: GetDirectParam. Found a non-token. About to throw.");
- THROW( errAEEventNotHandled );
- }
- } // GetDirectParam()
-